home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / POINTERS.SWG / 0007_PTRARRAY.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  1KB  |  48 lines

  1. DS> Hi, I've recently encountered a problem With not having enough memory
  2. DS> to open a large sized Array [ie: 0..900].  Is there any way to
  3. DS> allocate more memory to the Array as to make larger Arrays
  4.  
  5. Array of what?  if the total size of the Array (i.e. 901 *
  6. sizeof(whatever_it_is_you're_talking_about)) is less than 64K, it's a snap.
  7. Read your dox on Pointers and the heap.  You'll end up doing something like
  8. this:
  9.  
  10. Type
  11.   tWhatever : whatever_it_is_you're_talking_about;
  12.   tMyArray : Array[0..900] of tWhatever;
  13.   tPMyArray : ^MyArray;
  14.  
  15. Var
  16.   PMyArray : tPMyArray;
  17.  
  18. begin
  19.   getmem(PMyArray,sizeof(tMyArray));
  20.  
  21.   { now access your Array like this:
  22.     PMyArray^[IndexNo] }
  23.  
  24. if your Array is >64K, you can do something like this:
  25.  
  26. Type
  27.   tWhatever : whatever_it_is_you're_talking_about;
  28.   tPWhatever : ^tWhatever;
  29.  
  30. Var
  31.   MyArray : Array[0..900] of tPWhatever;
  32.   i : Word;
  33.  
  34. begin
  35.   For i := 0 to 900 do
  36.     getmem(MyArray[i],sizeof(tWhatever));
  37.  
  38.   { now access your Array like this:
  39.     MyArray[IndexNo]^ }
  40.  
  41. if you don't have enough room left in your data segment to use this latter
  42. approach (and I'll bet you do), you'll just need one more level of indirection.
  43. Declare one Pointer in the data segment that points to the Array of Pointers on
  44. the heap, which in turn point to your data.
  45.  
  46. if you're a beginner, this may seem impossibly Complex (it did to me), but keep
  47. at it and it will soon be second nature.
  48.